public class 二分法查找 {
    public static void main(String[] args) {
        int [] arr;
        arr=new int[]{1,2,3,4,5,6,7,8,9};
        int dest=1;
        int head=0;
        int end= arr.length-1;
        boolean isFlag=true;
        while (head<=end) {
            int middle=(head+end)/2;
            if (dest == arr[middle]) {
                System.out.println("你查找的dest值的索引值为："+middle);
                isFlag=false;
                break;

            }else if (dest > arr[middle]){
                head=middle+1;
            }else if (dest < arr[middle]){
                end=middle-1;
            }
        }
        if (isFlag) {
            System.out.println("你所查找的值不在这个数组中！");
        }
    }
}
